home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 21 / CU Amiga Magazine's Super CD-ROM 21 (1998)(EMAP Images)(GB)[!][issue 1998-04].iso / CUCD / Magazine / C_Tutorial / Part-6 / asl3 / main.c < prev    next >
C/C++ Source or Header  |  1997-10-27  |  2KB  |  101 lines

  1. #include<exec/libraries.h>
  2.  
  3. #include<stdio.h>
  4.  
  5. #include<clib/exec_protos.h>
  6.  
  7. #include "gui.h"
  8. #include "idcmp.h"
  9. #include "loadsave.h"
  10.  
  11. /* The library base global variables */
  12. /* (The different style of opening libraries requires these to be initialised to NULL) */
  13. struct Library* GfxBase = NULL;
  14. struct Library* IntuitionBase = NULL;
  15. struct Library* GadToolsBase = NULL;
  16. struct Library* AslBase = NULL;
  17. struct Library* DosBase = NULL;
  18. struct Library* IFFBase = NULL;
  19.  
  20. /* Need to give prototypes for our functions */
  21. int  createAll(void);
  22. void freeAll(void);
  23. int  openLibs(void);
  24. void closeLibs(void);
  25.  
  26. /* The initial screen depth */
  27. #define SCR_DEPTH (4)
  28.  
  29. /* The start of the program */
  30. void main()
  31. {
  32.     if(createAll())
  33.         handleIDCMP();
  34.     freeAll();
  35. }
  36.  
  37. int createAll()
  38. {
  39.     return openLibs() && openGUI(SCR_DEPTH,0,0,0);
  40. }
  41.  
  42. void freeAll()
  43. {
  44.     freeReqs();
  45.     closeGUI();
  46.     closeLibs();
  47. }
  48.  
  49. /* Try to open all the libraries -- return TRUE on success */
  50. int openLibs()
  51. {
  52.     if((GfxBase = OpenLibrary("graphics.library",37)) == NULL)
  53.     {
  54.         printf("Error: could not open graphics.library\n");
  55.         return FALSE;
  56.     }
  57.     if((IntuitionBase = OpenLibrary("intuition.library",37)) == NULL)
  58.     {
  59.         printf("Error: could not open intuition.library\n");
  60.         return FALSE;
  61.     }
  62.     if((GadToolsBase = OpenLibrary("gadtools.library",37)) == NULL)
  63.     {
  64.         printf("Error: could not open gadtools.library\n");
  65.         return FALSE;
  66.     }
  67.     if((AslBase = OpenLibrary("asl.library",37)) == NULL)
  68.     {
  69.         printf("Error: could not open asl.library\n");
  70.         return FALSE;
  71.     }
  72.     if((DosBase = OpenLibrary("dos.library",37)) == NULL)
  73.     {
  74.         printf("Error: could not open dos.library\n");
  75.         return FALSE;
  76.     }
  77.     if((IFFBase = OpenLibrary("iff.library",23)) == NULL)
  78.     {
  79.         printf("Error: could not open iff.library\n");
  80.         return FALSE;
  81.     }
  82.   return TRUE;
  83. }
  84.  
  85. /* Close any open library */
  86. void closeLibs()
  87. {
  88.     if(IFFBase)
  89.         CloseLibrary(IFFBase);
  90.     if(DosBase)
  91.         CloseLibrary(DosBase);
  92.     if(AslBase)
  93.         CloseLibrary(AslBase);
  94.     if(GadToolsBase)
  95.         CloseLibrary(GadToolsBase);
  96.     if(IntuitionBase)
  97.         CloseLibrary(IntuitionBase);
  98.     if(GfxBase)
  99.         CloseLibrary(GfxBase);
  100. }
  101.